import pygal
from 投骰子 import Die

# 掷骰子，记录点数
die = Die()
results = []
for i in range(100):
    results.append(die.roll())
#print(results)

# 统计各面出现次数
side_counts = []
for side in range(1, die.side_nums + 1):
    side_count = results.count(side)
    side_counts.append(side_count)
print(side_counts)

# 绘制直方图
hist = pygal.Bar()

hist.title = 'results of rolling one D6 100 times'
hist.x_labels = [i for i in range(1, die.side_nums + 1)]
hist.x_title = 'die'
hist.y_title = 'results'

#print(hist.x_labels)
hist.add('D6', side_counts)
hist.render_to_file('D6.svg')
